<?php

/*
 * This class is used for as Model for parent_list table 
 */

class Model_Parentlist extends Model_Base {

    protected $_name = 'tbl_parent_list';
    protected $_primaryKey = 'parent_id';

    /**
     *  This function is used to get contractors
     * @return null|Zend_Db_Table_Row_Abstract
     */
    public function fetchall($type) {
        $select = $this->select()
                ->from(array('con' => 'tbl_parent_list'))
                ->where('parent_status != 2')
                ->order('parent_name asc');
        #echo $select; exit;
        if ($type != '') {
            $select->where('parent_name ="' . $type . '"');
        }
        $data = parent::fetchAll($select);
        if (!empty($data)) {
            return $data->toArray();
        } else {
            return array();
        }
    }

    public function fetchParentListtype($where = "", $limit = "", $offset = "0", $order = 'parent_id', $sort = 'ASC') {
        $select = $this->select()
                ->from(array('parent' => 'tbl_parent_list'))
                ->where('parent_status != 2');
        if ($where != '') {
            $select->where($where);
        }
        if ($limit != "") {
            $select->limit($limit, $offset);
        }

        $select->order($order . " " . $sort);
        #echo $select; exit;
        $data = parent::fetchAll($select);
        if (!empty($data)) {
            return $data->toArray();
        } else {
            return array();
        }
    }

    public function fetchParentListCount($where) {
        $select = $this->select()
                ->from(array('parent' => 'tbl_parent_list'), Array('cnt' => 'count(*)'))
                ->where('parent_status != 2');
        if ($where != '') {
            $select->where($where);
        }
        $rows = parent::fetchRow($select);
        return($rows->cnt);
    }

}
